package com.budwk.app.sqfwV2.generator.povertyMonitoring;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.ExcelGenerateParam;
import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.ExcelRowDataParam;
import com.budwk.app.sqfwDoc.codeGeneratorV2.generate.BaseExcelGenerator;
import com.budwk.app.sqfwDoc.codeGeneratorV2.generate.ResultOfExcelDataInto;
import com.budwk.app.sqfwV2.dto.povertyMonitoring.QuarterStatisticalTableExcelDTO;
import com.budwk.app.sqfwV2.enums.povertyMonitoring.FormingMaterialEnum;
import com.budwk.app.util.poiUtils.excelPictureConfigBO.ExcelFileCreateParamBO;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author ZY.Wang
 * @since 2024/6/17
 */
public class QuarterStatisticalTableExcelGenerator extends BaseExcelGenerator {

    @Override
    protected void customerPopularHeaderData(Map<String, Object> excelParam, ExcelGenerateParam excelGenerateParam) {
        Map<String, Object> customerParamMap = excelGenerateParam.getCustomerParamMap();
        QuarterStatisticalTableExcelDTO excelDTO = (QuarterStatisticalTableExcelDTO) customerParamMap.get("quarterStatisticTableData");

        excelParam.put("year",excelDTO.getYear());
        excelParam.put("quarter",excelDTO.getQuarter());
        excelParam.put("lastYear",excelDTO.getLastYear());
    }

    @Override
    protected void customerPopularHeaderDataForAdmin(Map<String, Object> excelParam, ExcelGenerateParam excelGenerateParam) {

    }

    @Override
    protected void popularSheetDataList(List<Map<String, Object>> sheetDataMapList, ExcelGenerateParam excelGenerateParam) {

    }

    @Override
    protected ResultOfExcelDataInto judgeExcelHaveDataBeforeErgodic(Map<String, Object> excelParam, ExcelGenerateParam excelGenerateParam) {
        Map<String, Object> customerParamMap = excelGenerateParam.getCustomerParamMap();
        QuarterStatisticalTableExcelDTO excelDTO = (QuarterStatisticalTableExcelDTO) customerParamMap.get("quarterStatisticTableData");

        List<QuarterStatisticalTableExcelDTO.QuarterStatisticalTableExcelRowDataDTO> excelDataList = excelDTO.getRowDataList();

        if (excelDataList == null || excelDataList.size() <= 0) {
            ResultOfExcelDataInto resultOfExcelDataInto = new ResultOfExcelDataInto();
            resultOfExcelDataInto.setExcelHaveDataFlag(false);
            resultOfExcelDataInto.setRemark("暂无数据");
        }
        return null;
    }

    @Override
    protected boolean addRowDataCondition(ExcelRowDataParam rowDataParam, ExcelGenerateParam excelGenerateParam) {
        return true;
    }

    @Override
    protected void customerPopularSheetData(List<Map<String, Object>> listMap, ExcelGenerateParam excelGenerateParam) {

        Map<String, Object> customerParamMap = excelGenerateParam.getCustomerParamMap();
        QuarterStatisticalTableExcelDTO excelDTO = (QuarterStatisticalTableExcelDTO) customerParamMap.get("quarterStatisticTableData");
        List<QuarterStatisticalTableExcelDTO.QuarterStatisticalTableExcelRowDataDTO> excelDataList = excelDTO.getRowDataList();

        int num = 1;
        for (QuarterStatisticalTableExcelDTO.QuarterStatisticalTableExcelRowDataDTO excelRowQueryData : excelDataList) {
            Map<String, Object> rowData = Maps.newHashMap();
            JSONObject rowDataJson = JSONObject.parseObject(JSONObject.toJSONString(excelRowQueryData));
            rowData.putAll(rowDataJson);
            rowData.put("num",num);
            listMap.add(rowData);

            num++;
        }
    }

    @Override
    protected void customerPopularRowDataMap(Map<String, Object> rowDataMap, ExcelRowDataParam rowDataParam) {

    }

    @Override
    protected void customerPopularRowDataMapForAdmin(Map<String, Object> rowDataMap, ExcelRowDataParam rowDataParam) {

    }

    @Override
    protected ResultOfExcelDataInto judgeExcelHaveDataBeforeCreate(Map<String, Object> excelParam, ExcelGenerateParam excelGenerateParam) {
        return null;
    }

    @Override
    protected String getTemplatePath(ExcelGenerateParam excelGenerateParam) {
        return FormingMaterialEnum.D.getTemplat();
    }

    @Override
    protected String getDownloadFileName(ExcelGenerateParam excelGenerateParam) {
        return FormingMaterialEnum.D.getFileName() + "_" + DateUtil.format(new Date(), DatePattern.PURE_DATETIME_FORMAT);
    }

    @Override
    protected Class<?> getImageConfigBO() {
        return null;
    }

    @Override
    protected void completeExcelFileCreateParam(ExcelFileCreateParamBO excelFileCreateParamBO) {

    }
}
